<!DOCTYPE html>
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path ;

%>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="IMG/favicon.ico">


<title>人员管理</title>

<!-- Bootstrap core CSS -->
<link href="static/css/dist/css/bootstrap.min.css?v=1" rel="stylesheet">
<!-- Bootstrap theme -->
<link href="static/css/dist/css/bootstrap-theme.min.css" rel="stylesheet">
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="static/css/assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">

<!-- Custom styles for this template -->
<link href="static/css/theme.css" rel="stylesheet">
<script src="static/js/echarts.min.js"></script>
<!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
<!--[if lt IE 9]><script src="static/css/assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
<script src="static/css/assets/js/ie-emulation-modes-warning.js"></script>

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>

<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>

<![endif]-->
<script type="text/javascript">

window.onload = init;//传入函数地址
function init(){
    //用于添加页面
    var saleRegions = document.getElementById('saleRegions');
    saleRegions.onchange = function() {
        var cityEle = document.getElementById('saleDepartment');
        cityEle.innerHTML = ""; // 每次进来先清空城市列表
        var provinceValue = this.value;


        switch (provinceValue) {
            case "1":
                var cities = ['昆仑厅', '海世界厅']
                break;
            case "2":
                var cities = ['湘江厅', '河海厅']
                break;

        }
        for (var i = 0; i < cities.length; i++) {
            var option = document.createElement('option'); //先创建option
            var textNode = document.createTextNode(cities[i]); //再把城市名作为子节点填入，也可用innerHTML
            option.appendChild(textNode);
            cityEle.appendChild(option);
        }
    }

    //用于查询页面
    var searchSaleRegions = document.getElementById('searchSaleRegions');
    searchSaleRegions.onchange = function() {
        var searchSaleDepartment = document.getElementById('searchSaleDepartment');
        searchSaleDepartment.innerHTML = ""; // 每次进来先清空城市列表
        var searchSaleValue = this.value;


        switch (searchSaleValue) {
            case "1":
                var scities = ['昆仑厅', '海世界厅']
                break;
            case "2":
                var scities = ['湘江厅', '河海厅']
                break;

        }
        for (var i = 0; i < scities.length; i++) {
            var option = document.createElement('option'); //先创建option
            var textNode = document.createTextNode(scities[i]); //再把城市名作为子节点填入，也可用innerHTML
            option.appendChild(textNode);
            searchSaleDepartment.appendChild(option);
        }
    }


    //用于更改DIV
    var alertSaleRegions = document.getElementById('alertSaleRegions');
    alertSaleRegions.onchange = function() {
        var alterSaleDepartment = document.getElementById('altertSaleDepartment');
        alterSaleDepartment.innerHTML = ""; // 每次进来先清空城市列表
        var alterSaleValue = this.value;


        switch (alterSaleValue) {
            case "1":
                var altercities = ['昆仑厅', '海世界厅']
                break;
            case "2":
                var altercities = ['湘江厅', '河海厅']
                break;

        }
        for (var i = 0; i < altercities.length; i++) {
            var option = document.createElement('option'); //先创建option
            var textNode = document.createTextNode(altercities[i]); //再把城市名作为子节点填入，也可用innerHTML
            option.appendChild(textNode);
            alterSaleDepartment.appendChild(option);
        }
    }



}

function loadAlterModel(user_model_id) {
    var obj = {"userid": user_model_id};
    $.ajax({
        url: "<%= basePath %>/lookUserinfo",
        type: "POST",
        contentType: 'application/json;charset=utf-8', //设置请求头信息
        dataType: "json",
        data: JSON.stringify(obj),            //将Json对象序列化成Json字符串，toJSON()需要引用jquery.json.min.js
        success: function (data) {
            document.getElementById("userLoginName").value = data.info[0]["user_login_name"];
            document.getElementById("userRealName").value = data.info[0]["user_realname"];
            document.getElementById("userTelePhone").value = data.info[0]["user_phone"];
            document.getElementById("userId").value = data.info[0]["user_model_id"];

            //对于区域 对于营业厅的联动
            var alertSaleRegions = document.getElementById('alertSaleRegions');
            alertSaleRegions.innerHTML = ""; // 每次进来先清空城市列表


            if(data.info[0]["city"]=='1') {
                var option = document.createElement('option'); //先创建option
                var textNode = document.createTextNode('石家庄'); //再把城市名作为子节点填入，也可用innerHTML
                option.appendChild(textNode);
                option.setAttribute("value","1");
                alertSaleRegions.appendChild(option);

                var option1 = document.createElement('option'); //先创建option
                var textNode1 = document.createTextNode('保定'); //再把城市名作为子节点填入，也可用innerHTML
                option1.appendChild(textNode1);
                option1.setAttribute("value","2");
                alertSaleRegions.appendChild(option1);

            }else{
                var option = document.createElement('option'); //先创建option
                var textNode = document.createTextNode('保定'); //再把城市名作为子节点填入，也可用innerHTML
                option.appendChild(textNode);
                option.setAttribute("value","2");
                alertSaleRegions.appendChild(option);

                var option1 = document.createElement('option'); //先创建option
                var textNode1 = document.createTextNode('石家庄'); //再把城市名作为子节点填入，也可用innerHTML
                option1.appendChild(textNode1);
                option1.setAttribute("value","1");
                alertSaleRegions.appendChild(option1);
            }

            /**
             * 营业厅
             * @type {HTMLElement}
             */
            var alterSaleDepartment = document.getElementById('altertSaleDepartment');
            alterSaleDepartment.innerHTML = ""; // 每次进来先清空城市列表
            var optionD = document.createElement('option'); //先创建option
            var textNodeD = document.createTextNode(data.info[0]["location"]); //再把城市名作为子节点填入，也可用innerHTML
            optionD.appendChild(textNodeD);
            alterSaleDepartment.appendChild(optionD);

            if(data.info[0]["city"]=='1') {

                if(data.info[0]["location"]=='昆仑厅'){
                    var optionY = document.createElement('option'); //先创建option
                    var textNodeY = document.createTextNode('海世界厅'); //再把城市名作为子节点填入，也可用innerHTML
                    optionY.appendChild(textNodeY);
                    alterSaleDepartment.appendChild(optionY);
                }else{
                    var optionY = document.createElement('option'); //先创建option
                    var textNodeY = document.createTextNode('昆仑厅'); //再把城市名作为子节点填入，也可用innerHTML
                    optionY.appendChild(textNodeY);
                    alterSaleDepartment.appendChild(optionY);
                }

            }else{
                if(data.info[0]["location"]=='湘江厅'){
                    var optionY = document.createElement('option'); //先创建option
                    var textNodeY = document.createTextNode('河海厅'); //再把城市名作为子节点填入，也可用innerHTML
                    optionY.appendChild(textNodeY);
                    alterSaleDepartment.appendChild(optionY);
                }else{
                    var optionY = document.createElement('option'); //先创建option
                    var textNodeY = document.createTextNode('湘江厅'); //再把城市名作为子节点填入，也可用innerHTML
                    optionY.appendChild(textNodeY);
                    alterSaleDepartment.appendChild(optionY);
                }
            }
            /**
             * 营业厅
             * @type {HTMLElement}
             */


            var alterRoles = document.getElementById('alterRoles');
            alterRoles.innerHTML = ""; // 每次进来先清空城市列表

            if(data.info[0]["role"]=='1') {
                var option1 = document.createElement('option'); //先创建option
                var textNode1= document.createTextNode('店员'); //再把城市名作为子节点填入，也可用innerHTML
                option1.appendChild(textNode1);
                option1.setAttribute("value", "1");
                alterRoles.appendChild(option1);

                var option = document.createElement('option'); //先创建option
                var textNode = document.createTextNode('店长'); //再把城市名作为子节点填入，也可用innerHTML
                option.appendChild(textNode);
                option.setAttribute("value", "2");
                alterRoles.appendChild(option);
            }
            if(data.info[0]["role"]=='2') {
                var option = document.createElement('option'); //先创建option
                var textNode = document.createTextNode('店长'); //再把城市名作为子节点填入，也可用innerHTML
                option.appendChild(textNode);
                option.setAttribute("value", "2");
                alterRoles.appendChild(option);

                var option1 = document.createElement('option'); //先创建option
                var textNode1 = document.createTextNode('店员'); //再把城市名作为子节点填入，也可用innerHTML
                option1.appendChild(textNode1);
                option1.setAttribute("value", "1");
                alterRoles.appendChild(option1);
            }
            console.log(data);
        },
        error: function (res) {
            alert(res.responseText);
        }
    });
}



</script>
</head>

<body role="document">

<!-- Fixed navbar -->
<nav class="navbar navbar-inverse navbar-fixed-top">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="main">IBONUS</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
            <ul class="nav navbar-nav">
                <!--<li class="active"><a href="#"></a></li>-->
                <li><a href="salesGLYIntoPage"><span style="font-family:微软雅黑; ">销售统计</span></a></li>
                <li><a href="productGLYIntoPage"><span style="font-family:微软雅黑; ">产品奖励配置</span></a></li>
                <li><a href="userGLYIntoPage" class="active"><span style="font-family:微软雅黑; ">人员配置</span></a></li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">${userInfo.userRealname} <span class="caret"></span></a>
                    <ul class="dropdown-menu">
                        <li><a href="logout"><span style="font-family:微软雅黑; ">注销</span></a></li>
                        <li><a href="updatePasswordPage"><span style="font-family:微软雅黑; ">修改密码</span></a></li>
                    </ul>
                </li>
            </ul>
        </div><!--/.nav-collapse -->
    </div>
</nav>


<div class="container">

<!-- Main jumbotron for a primary marketing message or call to action -->

<div class="panel panel-default">
<!-- Default panel contents -->
<div class="panel-heading">
      <span style="font-family:微软雅黑;">
        人员配置页面
        <button type="button" id="loadButton" name="loadButton"  data-toggle="modal" data-target="#addModal" onClick="loadAddModel()" class="btn btn-default glyphicon glyphicon-plus" >

        </button>

        <button type="button" id="searchButton" name="searchButton"  data-toggle="modal" data-target="#searchModal" onClick="loadAddModel()" class="btn btn-default glyphicon glyphicon-search" >

        </button>
         <span style="color:red">${msg}</span>
      </span>
</div>
<div class="panel-body">
    <p><span style="font-family:微软雅黑;">此页面用于管理系统用户信息</span> </p>
</div>

<!-- Modal -->
<div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" style="font-family:微软雅黑;"id="addModalLabel">新建人员信息</h4>
            </div>
            <div class="modal-body" style="font-family:微软雅黑;">
                <form action="userGLYAddUser" method="post">
                    <div class="form-group">
                        <label for="exampleInputEmail1">员工工号</label>
                        <input  class="form-control" id="exampleInputEmail1" name="userLoginName"  >
                    </div>
                    <div class="form-group">
                        <label for="exampleInputEmail2">员工姓名</label>
                        <input  class="form-control" id="exampleInputEmail2" name="userRealName"  >
                    </div>
                    <div class="form-group">
                        <label for="exampleInputEmail3">手机</label>
                        <input  class="form-control" id="exampleInputEmail3" name="userTelePhone"  >
                    </div>
                    <div class="form-group">
                        <label for="saleRegions">所属地区</label>
                        <select class="form-control" id="saleRegions" name="saleRegions">
                            <option value="1">石家庄</option>
                            <option value="2">保定</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="saleDepartment">所属营业厅</label>
                        <select class="form-control" id="saleDepartment" name="saleDepartment">
                            <option>昆仑厅</option>
                            <option>海世界厅</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="addRoles">角色</label>
                        <select class="form-control" id="addRoles" name="addRoles">
                            <option value="2">店长</option>
                            <option value="1">店员</option>
                        </select>
                    </div>

                    <div class="form-group" align="right">
                        <button type="submit" id="addSales" name="addSales"   class="btn btn-primary" >添加</button>
                        <!--
                        <button type="submit" id="addEmail" name="addEmail"  class="btn btn-default" disabled >添加</button>
                        <button type="button" id="checkButton" name="checkButton" onClick="checkEmailValid()" class="btn btn-primary" >
                          检测
                        </button>
                        -->
                        &nbsp;&nbsp;&nbsp;
                    </div>
                </form>

            </div>

        </div>
    </div>
</div>

<!--更改店员配置页面-->
<div class="modal fade" id="alterModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" style="font-family:微软雅黑;"id="alterModalLabel">更改人员配置信息</h4>
            </div>
            <div class="modal-body" style="font-family:微软雅黑;">
                <form action="userGLYUpdateUser" name="updateForm" method="post">
                    <div class="form-group">
                        <label for="exampleInputEmail1">员工工号</label>
                        <input  class="form-control" id="userLoginName" name="alteruserLoginName" value="${userLoginName}" readonly>
                    </div>
                    <div class="form-group">
                        <label for="exampleInputEmail2">员工姓名</label>
                        <input  class="form-control" id="userRealName" name="alteruserRealName"  >
                    </div>
                    <div class="form-group">
                        <label for="exampleInputEmail3">手机</label>
                        <input  class="form-control" id="userTelePhone" name="alteruserTelePhone"  >
                    </div>
                    <div class="form-group">
                        <label for="alertSaleRegions">所属地区</label>
                        <select class="form-control" id="alertSaleRegions" name="altersaleDepartment">
                            <option value="1">石家庄</option>
                            <option value="2">保定</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="altertSaleDepartment">所属营业厅</label>
                        <select class="form-control" id="altertSaleDepartment" name="altertSaleDepartment">
                            <option>昆仑厅</option>
                            <option>海世界厅</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="alterRoles">角色</label>
                        <select class="form-control" id="alterRoles" name="alterRoles">
                            <option value="1">店长</option>
                            <option value="0">店员</option>
                        </select>
                    </div>

                    <div class="form-group" align="right">
                        <input type="hidden" name="userId" id="userId" />
                        <input type="hidden" name="userPassword" id="userPassword" value="1"/>
                        <button type="submit" id="alterSales" name="alterSales"   class="btn btn-primary" >更改</button>
                        <button type="submit" id="repassword" name="repassword"    class="btn btn-primary" >初始化密码</button>
                        <!--
                        <button type="submit" id="addEmail" name="addEmail"  class="btn btn-default" disabled >添加</button>
                        <button type="button" id="checkButton" name="checkButton" onClick="checkEmailValid()" class="btn btn-primary" >
                          检测
                        </button>
                        -->
                        &nbsp;&nbsp;&nbsp;
                    </div>
                </form>

            </div>

        </div>
    </div>
</div>

<!-- 查询条件加载 -->
<div class="modal fade" id="searchModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" style="font-family:微软雅黑;"id="searchModalLabel">查询条件</h4>
            </div>
            <div class="modal-body" style="font-family:微软雅黑;">
                <form action="userGLYSearchUser" method="post">
                    <div class="form-group">
                        <label for="searchLoginName">员工工号</label>
                        <input  class="form-control" id="searchLoginName" name="searchLoginName"  >
                    </div>
                    <div class="form-group">
                        <label for="searchRealName">员工姓名</label>
                        <input  class="form-control" id="searchRealName" name="searchRealName"  >
                    </div>
                    <div class="form-group">
                        <label for="searchTelePhone">手机</label>
                        <input  class="form-control" id="searchTelePhone" name="searchTelePhone"  >
                    </div>
                    <div class="form-group">
                        <label for="searchSaleRegions">所属地区</label>
                        <select class="form-control" id="searchSaleRegions" name="searchSaleRegions">
                            <option value="1">石家庄</option>
                            <option value="2">保定</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="searchSaleDepartment">所属营业厅</label>
                        <select class="form-control" id="searchSaleDepartment" name="searchSaleDepartment">
                            <option>昆仑厅</option>
                            <option>海世界厅</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="searchRoles">角色</label>
                        <select class="form-control" id="searchRoles" name="searchRoles">
                            <option value="-1">全部</option>
                            <option value="2">店长</option>
                            <option value="1">店员</option>
                        </select>
                    </div>

                    <div class="form-group" align="right">
                        <button type="submit" id="searchSales" name="searchSales"   class="btn btn-primary" >查找</button>
                        <!--
                        <button type="submit" id="addEmail" name="addEmail"  class="btn btn-default" disabled >添加</button>
                        <button type="button" id="checkButton" name="checkButton" onClick="checkEmailValid()" class="btn btn-primary" >
                          检测
                        </button>
                        -->
                        &nbsp;&nbsp;&nbsp;
                    </div>
                </form>

            </div>

        </div>
    </div>
</div>
<!-- Table -->

<table id="example" class="table table-hover table-condensed" style="font-family:微软雅黑;" >
    <thead>
    <tr>
        <th >店员姓名</th>
        <th>登录名</th>
        <th>区域</th>
        <th>所属营业厅</th>
        <th>角色</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>


    <c:forEach items="${userModelList}" var="x">
        <tr>
            <td>${x.user_realname}</td>
            <td>${x.user_login_name}</td>
            <td>
                <c:if test="${x.city==1}">
                    石家庄
                </c:if>
                <c:if test="${x.city==2}">
                    保定
                </c:if>
                <c:if test="${x.city==3}">
                    省
                </c:if>
            </td>
            <td>${x.location}</td>
            <td>
                <c:if test="${x.role==1}">
                    店员
                </c:if>

                <c:if test="${x.role==2}">
                    店长
                </c:if>
                <c:if test="${x.role==3}">
                    管理员
                </c:if>
            </td>
            <td>
                <button type="button" class="btn btn-default btn-xs glyphicon glyphicon-pencil" data-toggle="modal" data-target="#alterModal" onClick="loadAlterModel('${x.user_model_id}')"></button>
                &nbsp&nbsp
                <button type="button" class="btn btn-default btn-xs glyphicon glyphicon-trash" onclick="javascript:if(confirm('确定要删除此信息吗？')){window.location.href='/deteteRyInfo?userid=${x.user_model_id}'}return false;"></button>            </td>
        </tr>
    </c:forEach>

    </tbody>
</table>
</div>



<hr>
<footer>
    <p align="center">&copy; <span style="font-family:微软雅黑; ">copyright &nbsp;中国电信股份有限公司河北分公司企业信息化部 2016</span></p>
</footer>
</div> <!-- /container -->


<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->

<script src="static/js/jquery.min.js"></script>
<script src="static/css/dist/js/bootstrap.min.js"></script>
<script src="static/css/assets/js/docs.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="static/css/assets/js/ie10-viewport-bug-workaround.js"></script>
<!--
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
-->

<link rel="stylesheet" type="text/css" href="static/css/jquery.dataTables.css"/>

<script type="text/javascript" language="javascript" src="static/js/jquery.js"></script>
<script type="text/javascript" language="javascript" src="static/js/jquery.dataTables.js">
</script>
<script type="text/javascript" language="javascript" class="init">


    $(document).ready(function() {
        $('#example').DataTable({
            language: {
                processing:     "处理中...",
                search:         "搜索&nbsp;:",
                lengthMenu:    "显示 _MENU_ 项结果",
                info:           "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
                infoEmpty:      "显示第 0 至 0 项结果，共 0 项",
                infoFiltered:   "(由 _MAX_ 项结果过滤)",
                infoPostFix:    "",
                loadingRecords: "数据加载中...",
                zeroRecords:    "未找到匹配项",
                emptyTable:     "表中数据为空",
                paginate: {
                    first:      "第一页",
                    previous:   "上一页",
                    next:       "下一页",
                    last:       "尾页"
                },
                aria: {
                    sortAscending:  ": 以升序排列此列",
                    sortDescending: ": 以降序排列此列"
                }
            }
        } );
    } )
</script>
</body>
</html>
